var http=require("http");
var fs=require("fs");//文件系统模块
var path=require("path");
http.createServer((req,res)=>{
    res.writeHead(200,{"Content-Type":"text/html"})//状态码200表示服务端成功收到请求并可以正常响应
    /*
    向网页中添加图片
    */
    var filePath=path.join(__dirname,"/handsome.jpeg");
    var imgBuf=fs.readFileSync(filePath);//readFileSync同步读取文件
    var imgBase64=imgBuf.toString("base64");
    res.write("<!DOCTYPE html>"+
        "<head></head><body style='background:red'>"+
        "<img src='data:image/jpeg;base64,"+imgBase64+
        "'/>"+
        "</body></html>"
    )
    res.end();
}).listen(8081);

console.log("server is listening 8081");